package com.dong.thread.juc;

import java.util.concurrent.locks.LockSupport;

/**
 * 要求用两个线程顺序打印A1B2C3D4......Z26
 *
 * 自己思考：用LockSupport实现
 *
 * @author by jiweidong on 2021/11/28.
 */
public class T10_Interview_02_LockSupport {


    static String[] nums = {"1", "2", "3", "4", "5", "6", "7", "8", "9",
            "10", "11", "12", "13", "14", "15", "16", "17", "18",
            "19", "20", "21", "22", "23", "24", "25", "26"};

    static String[] letters = {"A", "B", "C", "D", "E", "F", "G", "H", "I",
            "G", "K", "L", "M", "N", "O", "P", "Q", "R",
            "S", "T", "U", "V", "W", "X", "Y", "Z"};


    static Thread t1;
    static Thread t2;

    public static void main(String[] args) {

        T10_Interview_02_LockSupport list = new T10_Interview_02_LockSupport();

        t1 = new Thread(() -> {
//            System.out.println("t1 started");
            for (String letter : letters) {
                System.out.print(letter);
                LockSupport.unpark(t2);
                LockSupport.park();
            }
        });

        t2 = new Thread(() -> {
//            System.out.println("t2 started");
            for (String num : nums) {
                LockSupport.park();
                System.out.print(num);
                LockSupport.unpark(t1);
            }
        });

        t1.start();
        t2.start();
    }

}
